﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StaffList.aspx.cs" Inherits="Base_School_StaffList" EnableEventValidation = "false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>课程列表</title>
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../Common/Js/jquery.js"></script>

    <script type="text/javascript" src="../Common/Js/common.js"></script>

    <script type="text/javascript" src="../Common/Js/msg.js"></script>

    <script type="text/javascript" src="../Common/Js/xTree/dhtmlxcommon.js"></script>

    <script type="text/javascript" src="../Common/Js/xTree/dhtmlxtree.js"></script>

    <link href="../Common/css/dhtmlxtree.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div class="oneTreeBody">
                    <div class="treeMain">
                        <div style="height: 95%; width: 170px; overflow: auto;" id="treeBox">
                        </div>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>

    <script type="text/javascript">
        window.onload = InitClassList;

        var activate = 1;
        var tree;

        function InitClassList()
        {
            tree=new dhtmlXTreeObject('treeBox',"100%","100%",0);
            tree.setImagePath("../Common/images/xTreeImgs/");
            
            // 构造行政树结构
            PageMethods.GetStaffInfo(
                function(succ){
                    if(succ.length > 0) {
                        for(var i = 0; i<succ.length; i++) {
                            if(succ[i].Type != 2) {
                                tree.insertNewChild(0, -(succ[i].RID << 8), succ[i].Caption, 0, "orgClose.png", "organization.png", "orgClose.png", "");
                            }
                        }
                    }
                    tree.setItemStyle(id,"../Common/css/");
                    tree.setOnClickHandler(treeOnClick);
                }, 
                function(err) { self.parent.showMassgeBox("提示",CAUSE_FAIL,1,null); }
            )
            

            var id = -1;
            var FirstID = 0;
            // 构造教研组
            var title = tree.insertNewChild(0, -2, '教研组', 0, "orgClose.png", "organization.png", "orgClose.png", "");
            PageMethods.InitCauseList(
                function(succ) {
                    if(succ.length > 0) {
                        for(var i = 0; i<succ.length; i++) {
                            if (FirstID == 0)
                                FirstID = succ[i].RID;

                            tree.insertNewChild(-2,succ[i].RID,succ[i].CauseName,0,"group.gif","group.gif","group.gif","");
                        }
                    }
                    else
                        self.parent.showMassgeBox("提示","不存在任何课程，请先添加课程",1,null);   

                    if (FirstID != 0) {
                        self.parent.currCauseID = FirstID;
                        tree.selectItem(self.parent.currCauseID, true);
                        self.parent.frames["right"].location  = "StaffGrid.aspx?id="+FirstID+"&type=Subject";
                    }

                    tree.setItemStyle(id,"../Common/css/");
                    tree.setOnClickHandler(treeOnClick);
                }, 
                function(err) { self.parent.showMassgeBox("提示",CAUSE_FAIL,1,null); }
            )
            
            // 构造年级组
            var gradeRoot = tree.insertNewChild(0, -1, '年级组', 0, "orgClose.png", "organization.png", "orgClose.png", "");
            PageMethods.GetGradeInfo(
                function(succ){
                    initGradeList(succ);
                    
                    tree.setItemStyle(id,"../Common/css/");
                    tree.setOnClickHandler(treeOnClick);
                }, 
                function(err) { self.parent.showMassgeBox("提示",CAUSE_FAIL,1,null); }
            )
        }
        
        // 构造年级组树
        function initGradeList(opt) {
            switch(opt) {
                case 0:
                    break;
                case 1:
                    tree.insertNewChild(-1,0x01ff,"一年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x02ff,"二年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x03ff,"三年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x04ff,"四年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x05ff,"五年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x06ff,"六年级",0,"group.gif","group.gif","group.gif","");
                    break;
                case 2:
                    tree.insertNewChild(-1,0x07ff,"初一",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x08ff,"初二",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x09ff,"初三",0,"group.gif","group.gif","group.gif","");
                    break;
                case 3:
                    tree.insertNewChild(-1,0x0aff,"高一",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x0bff,"高二",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x0cff,"高三",0,"group.gif","group.gif","group.gif","");
                    break;
                case 4:
                    tree.insertNewChild(-1,0x01ff,"一年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x02ff,"二年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x03ff,"三年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x04ff,"四年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x05ff,"五年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x06ff,"六年级",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x07ff,"初一",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x08ff,"初二",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x09ff,"初三",0,"group.gif","group.gif","group.gif","");
                    break;
                case 5:
                    tree.insertNewChild(-1,0x07ff,"初一",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x08ff,"初二",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x09ff,"初三",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x0aff,"高一",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x0bff,"高二",0,"group.gif","group.gif","group.gif","");
                    tree.insertNewChild(-1,0x0cff,"高三",0,"group.gif","group.gif","group.gif","");
                    break;
            }
        }

        // -1 年级组id (其下ID为id左移8)
        // -2 教研组id
        // -(ID左移8) 行政人员id
        // 
        //过滤用户信息，根据教研组分类
        function treeOnClick(id) {
            if(activate == 0) {
                tree.selectItem(self.parent.currCauseID, false);
                self.parent.frames["right"].showMassgeBox('提示','您还有未保存的项,请保存后再切换');
                return;
            }

            if(tree.hasChildren(id) <1) {
                var parentId = tree.getParentId(id);
                var type = "null";
                var realId = 0;
                // 行政人员
                if(parentId == 0) {
                    type = "Staff";
                    realId = -id >> 8;
                }
                // 年级组
                else if(parentId == -1) {
                    type = "Grade";
                    realId = id >> 8;
                }
                // 教研组
                else if(parentId == -2) {
                    type = "Subject";
                    realId = id;
                }
                self.parent.currCauseID = realId;
                self.parent.currType = type;
                self.parent.frames["right"].location  = "StaffGrid.aspx?id="+realId+"&type="+type;
            }
            else {
                if(self.parent.currCauseID != null && self.parent.currCauseID > 0)
                tree.selectItem(self.parent.currCauseID, false);
            }
        }
    </script>

</body>
</html>
